﻿using Common;
using Device;
using System;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using T68Control.Procdure;
using T68Control.S12L_M1;
using OpenFileDialog = Microsoft.Win32.OpenFileDialog;

namespace T68Control.ViewModel
{
    internal class DebugViewModel : NotifyBase
    {
        private double _RU_18_10001Voltage;

        public double RU_18_10001Voltage
        {
            get { return _RU_18_10001Voltage; }
            set
            {
                _RU_18_10001Voltage = value;
                this.DoNotify();
            }
        }

        private double _RU_18_10001Current;

        public double RU_18_10001Current
        {
            get { return _RU_18_10001Current; }
            set
            {
                _RU_18_10001Current = value;
                this.DoNotify();
            }
        }

        private int _IV3003TCH1Voltage;

        public int IV3003TCH1Voltage
        {
            get { return _IV3003TCH1Voltage; }
            set
            {
                _IV3003TCH1Voltage = value;
                this.DoNotify();
            }
        }

        private int _IV3003TCH2Voltage;

        public int IV3003TCH2Voltage
        {
            get { return _IV3003TCH2Voltage; }
            set
            {
                _IV3003TCH2Voltage = value;
                this.DoNotify();
            }
        }

        private int _IV3003TCH3Voltage;

        public int IV3003TCH3Voltage
        {
            get { return _IV3003TCH3Voltage; }
            set
            {
                _IV3003TCH3Voltage = value;
                this.DoNotify();
            }
        }

        private double _IV3003TCH1Current;

        public double IV3003TCH1Current
        {
            get { return _IV3003TCH1Current; }
            set
            {
                _IV3003TCH1Current = value;
                this.DoNotify();
            }
        }

        private double _IV3003TCH2Current;

        public double IV3003TCH2Current
        {
            get { return _IV3003TCH2Current; }
            set
            {
                _IV3003TCH2Current = value;
                this.DoNotify();
            }
        }

        private double _IV3003TCH3Current;

        public double IV3003TCH3Current
        {
            get { return _IV3003TCH3Current; }
            set
            {
                _IV3003TCH3Current = value;
                this.DoNotify();
            }
        }

        private string _tpIndex;

        public string TPIndex
        {
            get { return _tpIndex; }
            set
            {
                _tpIndex = value;
                this.DoNotify();
                if (value != null)
                {
                    RelaySlaveId = TestModul.Relays[value].SlaveId;
                    RelayChl = TestModul.Relays[value].Channel;
                }
            }
        }

        private int _RelaySlaveId;

        public int RelaySlaveId
        {
            get { return _RelaySlaveId; }
            set
            {
                _RelaySlaveId = value;
                this.DoNotify();
            }
        }

        private int _RelayChl;

        public int RelayChl
        {
            get { return _RelayChl; }
            set
            {
                _RelayChl = value;
                this.DoNotify();
            }
        }

        private int _motorSpeed;

        public int MotorSpeed
        {
            get { return _motorSpeed; }
            set
            {
                _motorSpeed = value;
                this.DoNotify();
            }
        }

        private int _snLength;

        public int SNLength
        {
            get { return _snLength; }
            set
            {
                _snLength = value;
                this.DoNotify();
            }
        }

        private string _configPath;

        public string ConfigPath
        {
            get { return _configPath; }
            set
            {
                _configPath = value;
                this.DoNotify();
            }
        }

        private string _reportPath;

        public string ReportPath
        {
            get { return _reportPath; }
            set
            {
                _reportPath = value;
                this.DoNotify();
            }
        }

        private string _reportBackupPath;

        public string ReportBackupPath
        {
            get { return _reportBackupPath; }
            set
            {
                _reportBackupPath = value;
                this.DoNotify();
            }
        }

        private string _failImagePath;

        public string FailImagePath
        {
            get { return _failImagePath; }
            set
            {
                _failImagePath = value;
                this.DoNotify();
            }
        }

        private string _log;

        public string Log
        {
            get { return _log; }
            set
            {
                _log = value;
                this.DoNotify();
            }
        }

        private string _visionFilePath;

        public string VisionFilePath
        {
            get { return _visionFilePath; }
            set
            {
                _visionFilePath = value;
                this.DoNotify();
            }
        }

        private bool _isOne;

        public bool IsOne
        {
            get { return _isOne; }
            set
            {
                _isOne = value;
                this.DoNotify();
            }
        }

        public ObservableCollection<string> TPIndexs { get; set; }
        public ObservableCollection<bool> DOStatus { get; set; }
        public ObservableCollection<bool> DIStatus { get; set; }
        private bool refresh = false;

        public DebugViewModel()
        {
            CalibrateMode1Command = new CommandBase(CalibrateMode1);
            LightModeCommand = new CommandBase(LightMode);

            RU_18_10001ONCommand = new CommandBase(RU_18_10001On);
            RU_18_10001OffCommand = new CommandBase(RU_18_10001Off);
            RU_18_10001ReadCommand = new CommandBase(RU_18_10001Read);
            RU_18_10001WriteCommand = new CommandBase(RU_18_10001Write);
            DM3058EReadCommand = new CommandBase(DM3058ERead);
            IV3003TSetCommand = new CommandBase(IV3003TSet);
            IV3003TPowerOnCommand = new CommandBase(IV3003TPowerOn);
            RelayOnCommand = new CommandBase(RelayOn);
            RelayOffCommand = new CommandBase(RelayOff);
            YDownCommand = new CommandBase(YDown);
            YUpCommand = new CommandBase(YUp);
            MotorStopCommand = new CommandBase(MotorStop);
            RelayReadCommand = new CommandBase(RelayRead);
            RelayOffAllCommand = new CommandBase(RelayOffAll);
            LoadTestConfigCommand = new CommandBase(LoadTestConfig);
            LoadVisionFileCommand = new CommandBase(LoadVisionFile);
            SaveConfigCommand = new CommandBase(SaveConfig);

            SelectReportPathCommand = new CommandBase(SelectReportPath);
            SelectReportBackupPathCommand = new CommandBase(SelectReportBackupPath);
            SelectFailPathCommand = new CommandBase(SelectFailImagePath);
            CANFDConnectCommand = new CommandBase(CANFDConnect);
            CANFDDisConnectCommand = new CommandBase(CANFDDisConnect);
            try
            {
                var config = Config.Load();

                RU_18_10001Voltage = config.RU_18_10001Voltage;
                RU_18_10001Current = config.RU_18_10001Current;
                IV3003TCH1Voltage = config.IV3003TCH1Voltage;
                IV3003TCH1Current = config.IV3003TCH1Current;
                IV3003TCH2Voltage = config.IV3003TCH2Voltage;
                IV3003TCH2Current = config.IV3003TCH2Current;
                IV3003TCH3Voltage = config.IV3003TCH3Voltage;
                IV3003TCH3Current = config.IV3003TCH3Current;
                RelaySlaveId = 1;
                RelayChl = 1;
                MotorSpeed = 500;

                SNLength = config.SNLength;
                ConfigPath = config.TestFilePath;
                ReportPath = config.ReportDirectory;
                VisionFilePath = config.VisionFilePath;
                ReportBackupPath = config.ReportBackupDirectory;
                FailImagePath = config.FailImagePath;

                IsOne = config.IsOneProduct;
                LoadTPIndexs();
                DIStatus = new ObservableCollection<bool>();
                for (int i = 0; i < 16; i++)
                {
                    DIStatus.Add(false);
                }
                DOStatus = new ObservableCollection<bool>();
                for (int i = 0; i < 16; i++)
                {
                    DOStatus.Add(false);
                }
                Task.Run(() =>
                {
                    while (true)
                    {
                        try
                        {
                            refresh = true;
                            if (Machine.IOModule is null)
                            {
                                break;
                            }
                            for (int i = 0; i < 8; i++)
                            {
                                DIStatus[i] = Machine.IOModule.GetDIValue(i);
                            }
                            for (int i = 0; i < 8; i++)
                            {
                                DOStatus[i] = Machine.IOModule.GetDOValue(i);
                            }
                            refresh = false;
                            Thread.Sleep(500);
                        }
                        catch (Exception ex)
                        {
                            Mylog.Error(ex, ex.Message);
                        }
                    }
                });
                DOStatus.CollectionChanged += DOStatus_CollectionChanged;
            }
            catch (Exception ex)
            {
                Mylog.Error(ex, ex.Message);
                Log = ex.Message;
            }
        }

        private void CalibrateMode1(object obj)
        {
            if (Global.IsBusy)
            {
                Log = "正在执行其他操作,请完成后再尝试!";
                return;
            }
            Global.IsBusy = true;
            try
            {
                int mode = int.Parse(obj.ToString());

                string desc = null;
                VisionProcessID id = 0;
                string filePath = "";

                switch (mode)
                {
                    case 1:
                        filePath = Global.OddLinePointFile;
                        desc = "奇数行测试";
                        id = VisionProcessID.OddLine;
                        break;

                    case 2:
                        filePath = Global.EvenLinePointFile;
                        desc = "偶数行测试";
                        id = VisionProcessID.EvenLine;
                        break;

                    case 3:
                        filePath = Global.OddColumnPointFile;
                        desc = "奇数列测试";
                        id = VisionProcessID.OddColumn;
                        break;

                    case 4:
                        filePath = Global.EvenColumnPointFile;
                        desc = "偶数列测试";
                        id = VisionProcessID.EvenColumn;
                        break;

                    default:
                        break;
                }
                Global.TcpServer.ReceiveReady();
                Global.T68.SetStrongControlMode(mode);
                Thread.Sleep(1000);

                VisionMasterHelper.ExecVisionFlow(desc, (uint)id);
                Global.T68.ExitStrongControlMode();
                Global.TcpServer.WaitReceiveFinish();
                var ledRetStr = Global.TcpServer.Data;

                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                File.WriteAllText(filePath, ledRetStr);
                Log = $"mode={mode}标定完成";
            }
            catch (Exception ex)
            {
                Log = ex.Message;
            }
            finally
            {
                Global.IsBusy = false;
            }
        }

        private void LightMode(object obj)
        {
            if (Global.IsBusy)
            {
                Log = "正在执行其他操作,请完成后再尝试!";
                return;
            }
            Global.IsBusy = true;
            try
            {
                int mode = int.Parse(obj.ToString());
                switch (mode)
                {
                    case 0:
                        Global.T68.StopCharging();

                        break;

                    case 1:
                        Task.Run(() =>
                        {
                            //Global.T68.StartCharging();
                            Global.T68.SetStrongControlMode(mode);
                        });
                        break;

                    case 2:
                        Task.Run(() =>
                        {
                            //Global.T68.StartCharging();
                            Global.T68.SetStrongControlMode(mode);
                        });
                        break;

                    case 3:
                        Task.Run(() =>
                        {
                            //Global.T68.StartCharging();
                            Global.T68.SetStrongControlMode(mode);
                        });
                        break;

                    case 4:
                        Task.Run(() =>
                        {
                            //Global.T68.StartCharging();
                            Global.T68.SetStrongControlMode(mode);
                        });
                        break;

                    case 5:
                        Task.Run(() =>
                        {
                            //Global.T68.StartCharging();
                            Global.T68.SetStrongControlMode(mode);
                        });
                        break;

                    default:
                        break;
                }
            }
            catch (Exception ex)
            {
                Log = ex.Message;
            }
            finally
            {
                Global.IsBusy = false;
            }
        }

        private void LoadVisionFile(object obj)
        {
            if (Global.IsBusy)
            {
                Log = "正在执行其他操作,请完成后再尝试!";
                return;
            }
            Global.IsBusy = true;
            try
            {
                OpenFileDialog openFileDialog = new OpenFileDialog
                {
                    Filter = "sol文件 (*.sol)|*.sol",
                    Title = "选择一个sol文件",
                };
                if (openFileDialog.ShowDialog() == true)
                {
                    string selectedFilePath = openFileDialog.FileName;
                    VisionFilePath = selectedFilePath;
                }
            }
            catch (Exception ex)
            {
                Log = ex.Message;
            }
            finally
            {
                Global.IsBusy = false;
            }
        }

        private void CANFDConnect(object obj)
        {
            if (Global.IsBusy)
            {
                Log = "正在执行其他操作,请完成后再尝试!";
                return;
            }
            Global.IsBusy = true;
            try
            {
                Global.T68.Init();
            }
            catch (Exception ex)
            {
                Log = ex.Message;
            }
            finally
            {
                Global.IsBusy = false;
            }
        }

        private void CANFDDisConnect(object obj)
        {
            Task.Run(() =>
            {
                if (Global.IsBusy)
                {
                    Log = "正在执行其他操作,请完成后再尝试!";
                    return;
                }
                Global.IsBusy = true;
                try
                {
                    Global.T68.Close();
                }
                catch (Exception ex)
                {
                    Log = ex.Message;
                }
                finally
                {
                    Global.IsBusy = false;
                }
            });
        }

        private void SelectFailImagePath(object obj)
        {
            if (Global.IsBusy)
            {
                Log = "正在执行其他操作,请完成后再尝试!";
                return;
            }
            Global.IsBusy = true;
            try
            {
                using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog())
                {
                    folderBrowserDialog.Description = "请选择一个文件夹";
                    folderBrowserDialog.ShowNewFolderButton = true;

                    if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
                    {
                        string selectedPath = folderBrowserDialog.SelectedPath;
                        FailImagePath = selectedPath;
                    }
                }
            }
            catch (Exception ex)
            {
                Log = ex.Message;
            }
            finally
            {
                Global.IsBusy = false;
            }
        }

        private void SelectReportBackupPath(object obj)
        {
            if (Global.IsBusy)
            {
                Log = "正在执行其他操作,请完成后再尝试!";
                return;
            }
            Global.IsBusy = true;
            try
            {
                using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog())
                {
                    folderBrowserDialog.Description = "请选择一个文件夹";
                    folderBrowserDialog.ShowNewFolderButton = true;

                    if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
                    {
                        string selectedPath = folderBrowserDialog.SelectedPath;
                        ReportBackupPath = selectedPath;
                    }
                }
            }
            catch (Exception ex)
            {
                Log = ex.Message;
            }
            finally
            {
                Global.IsBusy = false;
            }
        }

        private void SelectReportPath(object obj)
        {
            if (Global.IsBusy)
            {
                Log = "正在执行其他操作,请完成后再尝试!";
                return;
            }
            Global.IsBusy = true;
            try
            {
                using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog())
                {
                    folderBrowserDialog.Description = "请选择一个文件夹";
                    folderBrowserDialog.ShowNewFolderButton = true;

                    if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
                    {
                        string selectedPath = folderBrowserDialog.SelectedPath;
                        ReportPath = selectedPath;
                    }
                }
            }
            catch (Exception ex)
            {
                Log = ex.Message;
            }
            finally
            {
                Global.IsBusy = false;
            }
        }

        private void SaveConfig(object obj)
        {
            if (Global.IsBusy)
            {
                Log = "正在执行其他操作,请完成后再尝试!";
                return;
            }
            Global.IsBusy = true;
            try
            {
                var config = Config.Load();
                config.SNLength = SNLength;
                config.TestFilePath = ConfigPath;
                config.VisionFilePath = VisionFilePath;
                config.ReportDirectory = ReportPath;
                config.FailImagePath = FailImagePath;
                config.ReportBackupDirectory = ReportBackupPath;

                config.RU_18_10001Voltage = RU_18_10001Voltage;
                config.RU_18_10001Current = RU_18_10001Current;
                config.IV3003TCH1Voltage = IV3003TCH1Voltage;
                config.IV3003TCH1Current = IV3003TCH1Current;
                config.IV3003TCH2Voltage = IV3003TCH2Voltage;
                config.IV3003TCH2Current = IV3003TCH2Current;
                config.IV3003TCH3Voltage = IV3003TCH3Voltage;
                config.IV3003TCH3Current = IV3003TCH3Current;

                config.IsOneProduct = IsOne;
                //config.Boot = Param1;
                //config.AppVersion = Param2;
                //config.SubAppVersion = Param3;
                //config.Current[0] = Param4;
                //config.Current[1] = Param5;
                //config.Current[2] = Param6;
                //config.Current[3] = Param7;
                //config.Current[4] = Param8;
                //config.Current[5] = Param9;
                //config.Current[6] = Param10;
                //config.Current[7] = Param11;
                //config.Current[8] = Param12;
                //config.Current[9] = Param13;
                Config.Save(config);
                Global.IsConfigChanged = true;
            }
            catch (Exception ex)
            {
                Log = ex.Message;
            }
            finally
            {
                Global.IsBusy = false;
            }
        }

        private void LoadTestConfig(object obj)
        {
            if (Global.IsBusy)
            {
                Log = "正在执行其他操作,请完成后再尝试!";
                return;
            }
            Global.IsBusy = true;
            try
            {
                OpenFileDialog openFileDialog = new OpenFileDialog
                {
                    Filter = "Excel Files (*.xlsx)|*.xlsx",
                    Title = "选择一个Excel文件",
                };
                if (openFileDialog.ShowDialog() == true)
                {
                    string selectedFilePath = openFileDialog.FileName;
                    ConfigPath = selectedFilePath;
                }
            }
            catch (Exception ex)
            {
                Log = ex.Message;
            }
            finally
            {
                Global.IsBusy = false;
            }
        }

        private void MotorStop(object obj)
        {
            if (Global.IsBusy)
            {
                Log = "正在执行其他操作,请完成后再尝试!";
                return;
            }
            Global.IsBusy = true;
            try
            {
                Machine.LC10P.MotorSpeed(0);
            }
            catch (Exception ex)
            {
                Log = ex.Message;
            }
            finally
            {
                Global.IsBusy = false;
            }
        }

        private void RelayOffAll(object obj)
        {
            if (Global.IsBusy)
            {
                Log = "正在执行其他操作,请完成后再尝试!";
                return;
            }
            Global.IsBusy = true;
            try
            {
                PQW_IO.OffAll(RelaySlaveId);
            }
            catch (Exception ex)
            {
                Log = ex.Message;
            }
            finally
            {
                Global.IsBusy = false;
            }
        }

        private void RelayRead(object obj)
        {
            if (Global.IsSafeLine)
            {
                Log = "安全光幕触发!";
                return;
            }
            if (Global.IsBusy)
            {
                Log = "正在执行其他操作,请完成后再尝试!";
                return;
            }
            Global.IsBusy = true;
            try
            {
                string sts = PQW_IO.GetDO(RelaySlaveId, RelayChl) ? "打开" : "关闭";
                Log = $"从机[{RelaySlaveId}]通道[{RelayChl}]状态[{sts}]";
            }
            catch (Exception ex)
            {
                Log = ex.Message;
            }
            finally
            {
                Global.IsBusy = false;
            }
        }

        private void DOStatus_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (!refresh)
            {
                int index = e.NewStartingIndex;
                int value = (sender as ObservableCollection<bool>)[index] ? 1 : 0;
                Machine.IOModule.SetDOValue(index, value);
            }
        }

        private void YUp(object obj)
        {
            if (Global.IsBusy)
            {
                Log = "正在执行其他操作,请完成后再尝试!";
                return;
            }
            Global.IsBusy = true;
            try
            {
                Machine.LC10P.MotorSpeed(-Math.Abs(MotorSpeed));
            }
            catch (Exception ex)
            {
                Log = ex.Message;
            }
            finally
            {
                Global.IsBusy = false;
            }
        }

        private void YDown(object obj)
        {
            if (Global.IsBusy)
            {
                Log = "正在执行其他操作,请完成后再尝试!";
                return;
            }
            Global.IsBusy = true;
            try
            {
                Machine.LC10P.MotorSpeed(Math.Abs(MotorSpeed));
            }
            catch (Exception ex)
            {
                Log = ex.Message;
            }
            finally
            {
                Global.IsBusy = false;
            }
        }

        private void RelayOff(object obj)
        {
            if (Global.IsBusy)
            {
                Log = "正在执行其他操作,请完成后再尝试!";
                return;
            }
            Global.IsBusy = true;
            try
            {
                PQW_IO.SetDO(RelaySlaveId, RelayChl, false);
            }
            catch (Exception ex)
            {
                Log = ex.Message;
            }
            finally
            {
                Global.IsBusy = false;
            }
        }

        private void RelayOn(object obj)
        {
            if (Global.IsBusy)
            {
                Log = "正在执行其他操作,请完成后再尝试!";
                return;
            }
            Global.IsBusy = true;
            try
            {
                PQW_IO.SetDO(RelaySlaveId, RelayChl, true);
            }
            catch (Exception ex)
            {
                Log = ex.Message;
            }
            finally
            {
                Global.IsBusy = false;
            }
        }

        private void LoadTPIndexs()
        {
            TPIndexs = new ObservableCollection<string>();
            foreach (var item in TestModul.Relays)
            {
                TPIndexs.Add(item.Key);
            }
        }

        private void IV3003TPowerOn(object obj)
        {
            if (Global.IsBusy)
            {
                Log = "正在执行其他操作,请完成后再尝试!";
                return;
            }
            Global.IsBusy = true;
            try
            {
                IV_3003T.SetChStatus(1);
            }
            catch (Exception ex)
            {
                Log = ex.Message;
            }
            finally
            {
                Global.IsBusy = false;
            }
        }

        private void IV3003TSet(object obj)
        {
            if (Global.IsBusy)
            {
                Log = "正在执行其他操作,请完成后再尝试!";
                return;
            }
            Global.IsBusy = true;
            try
            {
                IV_3003T.SwitchCh((IV3003T_CH_ENUM)1);
                IV_3003T.SetVoltage(IV3003TCH1Voltage);
                IV_3003T.SetCurrent(IV3003TCH1Current);
                IV_3003T.SwitchCh((IV3003T_CH_ENUM)2);
                IV_3003T.SetVoltage(IV3003TCH2Voltage);
                IV_3003T.SetCurrent(IV3003TCH2Current);
                IV_3003T.SwitchCh((IV3003T_CH_ENUM)3);
                IV_3003T.SetVoltage(IV3003TCH3Voltage);
                IV_3003T.SetCurrent(IV3003TCH3Current);
            }
            catch (Exception ex)
            {
                Log = ex.Message;
            }
            finally
            {
                Global.IsBusy = false;
            }
        }

        private void DM3058ERead(object obj)
        {
            if (Global.IsBusy)
            {
                Log = "正在执行其他操作,请完成后再尝试!";
                return;
            }
            Global.IsBusy = true;
            try
            {
                DM3058E.SetFunction(Function.DCI);
                double vol = DM3058E.GetValue();
                Log = $"电流读值{vol}A";
            }
            catch (Exception ex)
            {
                Log = ex.Message;
            }
            finally
            {
                Global.IsBusy = false;
            }
        }

        private void RU_18_10001Write(object obj)
        {
            if (Global.IsBusy)
            {
                Log = "正在执行其他操作,请完成后再尝试!";
                return;
            }
            Global.IsBusy = true;
            try
            {
                RU_18_10001.SetVoltage(RU_18_10001Voltage);
                RU_18_10001.SetCurrent(RU_18_10001Current);
            }
            catch (Exception ex)
            {
                Log = ex.Message;
            }
            finally
            {
                Global.IsBusy = false;
            }
        }

        private void RU_18_10001Read(object obj)
        {
            if (Global.IsBusy)
            {
                Log = "正在执行其他操作,请完成后再尝试!";
                return;
            }
            Global.IsBusy = true;
            try
            {
                double vol = RU_18_10001.GetVoltage();
                double cur = RU_18_10001.GetCurrent();
                Log = $"输出电压{vol}V, 输出电流{cur}A";
            }
            catch (Exception ex)
            {
                Log = ex.Message;
            }
            finally
            {
                Global.IsBusy = false;
            }
        }

        private void RU_18_10001On(object obj)
        {
            if (Global.IsBusy)
            {
                Log = "正在执行其他操作,请完成后再尝试!";
                return;
            }
            Global.IsBusy = true;
            try
            {
                RU_18_10001.SetStatus(true);
            }
            catch (Exception ex)
            {
                Log = ex.Message;
            }
            finally
            {
                Global.IsBusy = false;
            }
        }

        private void RU_18_10001Off(object obj)
        {
            if (Global.IsBusy)
            {
                Log = "正在执行其他操作,请完成后再尝试!";
                return;
            }
            Global.IsBusy = true;
            try
            {
                RU_18_10001.SetStatus(false);
            }
            catch (Exception ex)
            {
                Log = ex.Message;
            }
            finally
            {
                Global.IsBusy = false;
            }
        }

        private string _param1;

        public string Param1
        {
            get { return _param1; }
            set
            {
                _param1 = value;
                this.DoNotify();
            }
        }

        private string _param2;

        public string Param2
        {
            get { return _param2; }
            set
            {
                _param2 = value;
                this.DoNotify();
            }
        }

        private string _param3;

        public string Param3
        {
            get { return _param3; }
            set
            {
                _param3 = value;
                this.DoNotify();
            }
        }

        private double _param4;

        public double Param4
        {
            get { return _param4; }
            set
            {
                _param4 = value;
                this.DoNotify();
            }
        }

        private double _param5;

        public double Param5
        {
            get { return _param5; }
            set
            {
                _param5 = value;
                this.DoNotify();
            }
        }

        private double _param6;

        public double Param6
        {
            get { return _param6; }
            set
            {
                _param6 = value;
                this.DoNotify();
            }
        }

        private double _param7;

        public double Param7
        {
            get { return _param7; }
            set
            {
                _param7 = value;
                this.DoNotify();
            }
        }

        private double _param8;

        public double Param8
        {
            get { return _param8; }
            set
            {
                _param8 = value;
                this.DoNotify();
            }
        }

        private double _param9;

        public double Param9
        {
            get { return _param9; }
            set
            {
                _param9 = value;
                this.DoNotify();
            }
        }

        private double _param10;

        public double Param10
        {
            get { return _param10; }
            set
            {
                _param10 = value;
                this.DoNotify();
            }
        }

        private double _param11;

        public double Param11
        {
            get { return _param11; }
            set
            {
                _param11 = value;
                this.DoNotify();
            }
        }

        private double _param12;

        public double Param12
        {
            get { return _param12; }
            set
            {
                _param12 = value;
                this.DoNotify();
            }
        }

        private double _param13;

        public double Param13
        {
            get { return _param13; }
            set
            {
                _param13 = value;
                this.DoNotify();
            }
        }

        public CommandBase CalibrateMode1Command { get; set; }

        public CommandBase LightModeCommand { get; set; }

        public CommandBase RU_18_10001ONCommand { get; set; }
        public CommandBase RU_18_10001OffCommand { get; set; }
        public CommandBase RU_18_10001ReadCommand { get; set; }
        public CommandBase RU_18_10001WriteCommand { get; set; }
        public CommandBase DM3058EReadCommand { get; set; }

        public CommandBase IV3003TSetCommand { get; set; }
        public CommandBase IV3003TPowerOnCommand { get; set; }
        public CommandBase RelayOnCommand { get; set; }
        public CommandBase RelayOffCommand { get; set; }
        public CommandBase YDownCommand { get; set; }
        public CommandBase YUpCommand { get; set; }

        public CommandBase RelayReadCommand { get; set; }
        public CommandBase RelayOffAllCommand { get; set; }

        public CommandBase MotorStopCommand { get; set; }
        public CommandBase LoadTestConfigCommand { get; set; }
        public CommandBase SaveConfigCommand { get; set; }
        public CommandBase SelectReportPathCommand { get; set; }
        public CommandBase SelectReportBackupPathCommand { get; set; }
        public CommandBase SelectFailPathCommand { get; set; }
        public CommandBase CalibrateQG1Command { get; set; }
        public CommandBase CalibrateQG2Command { get; set; }
        public CommandBase LowLightCommand { get; set; }
        public CommandBase MidLightCommand { get; set; }
        public CommandBase HighLightCommand { get; set; }
        public CommandBase QG1LightCommand { get; set; }
        public CommandBase QG2LightCommand { get; set; }
        public CommandBase CANFDConnectCommand { get; set; }
        public CommandBase CANFDDisConnectCommand { get; set; }

        public CommandBase CANFDCloseCommand { get; set; }
        public CommandBase LoadVisionFileCommand { get; set; }
    }
}